﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace BadassPhotoAlbum
{
    /****************************************************************************
     * Created by: Mike flood, Adam Reaves and Joseph Alfred
     * This class is used to manage the information related to each photo. It handles
     * the hash value of the picture, description, ID and file descriptor.
     * *************************************************************************/
    public class Photo
    {
        private int hashValue;
        private string photoName;
        private string photoDescription;
        private int photoID;
        private Stream fileDescriptor;

        /******************************************************************************
         * This is the constructor for creating a photo. It takes an id, desctiption and the path
         * to the file. The fileDescriptor is based on the path of the picture and is then
         * used to create a hashValue for the picture to ensure duplicate photos are not
         * added.
         * *****************************************************************************/
        public Photo(string name, int id, string description, string path)
        {
            photoName = name;
            photoID = id;
            photoDescription = description;

            try
            {
                fileDescriptor = File.Open(path, FileMode.Open);
                hashValue = Database.GenerateHash(fileDescriptor);
            }
            catch
            {
                return;
            }
        }

        /**************************************************
         * This function is used to get and set the value 
         * of the photo name.
         * ************************************************/
        public string PhotoName
        {
            get { return photoName; }
            set { photoName = value; }
        }

        /**************************************************
        * This function is used to get and set the value 
        * of the photo description.
        * ************************************************/
        public string PhotoDescription
        {
            get { return photoDescription; }
            set { photoDescription = value; }
        }

        /**************************************************
        * This function is used to get the photoID
        * ************************************************/
        public int GetPhotoID()
        {
            return photoID;
        }

        /*******************************************************
        * This function is used to get the fileDescriptor value
        * *****************************************************/
        public Stream GetFileDescriptor()
        {
            return fileDescriptor;
        }

        /************************************************************
        * This function is used to get the hash value of the picture
        * **********************************************************/
        public int GetHashValue()
        {
            return hashValue;
        }
    }
}